package org.charles.zhifou.common.exception;


import org.charles.zhifou.common.response.ResponseCodeEnum;

/**
 * <h1>异常抛出工具类</h1>
 *
 * @author charles
 * @version 1.0
 */
public class ThrowUtils {

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param runtimeException
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param ResponseCodeEnum
     */
    public static void throwIf(boolean condition, ResponseCodeEnum responseCodeEnum) {
        throwIf(condition, new BusinessException(responseCodeEnum));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param ResponseCodeEnum
     * @param message
     */
    public static void throwIf(boolean condition, ResponseCodeEnum responseCodeEnum, String message) {
        throwIf(condition, new BusinessException(responseCodeEnum, message));
    }
}
